package com.cykj.product.controller;


import com.cykj.common.core.utils.poi.ExcelUtil;
import com.cykj.common.core.web.controller.BaseController;
import com.cykj.common.core.web.domain.AjaxResult;
import com.cykj.common.core.web.page.TableDataInfo;
import com.cykj.common.log.annotation.Log;
import com.cykj.common.log.enums.BusinessType;
import com.cykj.common.security.annotation.RequiresPermissions;
import com.cykj.product.domain.BsProductCategory;
import com.cykj.product.service.IBsProductCategoryService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品类目Controller
 * 
 * @author 天才少年
 * @date 2025-08-20
 */
@RestController
@RequestMapping("/category")
public class BsProductCategoryController extends BaseController
{
    @Autowired
    private IBsProductCategoryService bsProductCategoryService;

    /**
     * 查询商品类目列表
     */
    @com.cykj.common.security.annotation.RequiresPermissions("category:category:list")
    @GetMapping("/list")
    public TableDataInfo list(BsProductCategory bsProductCategory)
    {
        startPage();
        List<BsProductCategory> list = bsProductCategoryService.selectBsProductCategoryList(bsProductCategory);
        return getDataTable(list);
    }

    /**
     * 导出商品类目列表
     */
    @RequiresPermissions("category:category:export")
    @Log(title = "商品类目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BsProductCategory bsProductCategory)
    {
        List<BsProductCategory> list = bsProductCategoryService.selectBsProductCategoryList(bsProductCategory);
        ExcelUtil<BsProductCategory> util = new ExcelUtil<BsProductCategory>(BsProductCategory.class);
        util.exportExcel(response, list, "商品类目数据");
    }

    /**
     * 获取商品类目详细信息
     */
    @RequiresPermissions("category:category:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bsProductCategoryService.selectBsProductCategoryById(id));
    }

    /**
     * 新增商品类目
     */
    @RequiresPermissions("category:category:add")
    @Log(title = "商品类目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BsProductCategory bsProductCategory)
    {
        return toAjax(bsProductCategoryService.insertBsProductCategory(bsProductCategory));
    }

    /**
     * 修改商品类目
     */
    @RequiresPermissions("category:category:edit")
    @Log(title = "商品类目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BsProductCategory bsProductCategory)
    {
        return toAjax(bsProductCategoryService.updateBsProductCategory(bsProductCategory));
    }

    /**
     * 删除商品类目
     */
    @PutMapping("/{id}")
   public AjaxResult remove(@PathVariable Long id){
       return toAjax(bsProductCategoryService.deleteBsProductCategoryById(id));
   }
   //批量删除
    @PutMapping("/batch")
    public AjaxResult removeList(@RequestBody List<Long> ids){
        return toAjax(bsProductCategoryService.deleteBsProductCategoryByIds(ids));
    }
}
